package com.cskaoyan._01basic._08loop._02test;

import java.util.Random;
import java.util.Scanner;

/**
 * @author Macro_Ray
 * @since 2024/3/4 17:59
 */
/*获取一个0-100的随机数，并用程序猜到这个数
 * */
public class _08Advenced_05 {
    public static void main(String[] args) {
        // 1.生成一个随机数
        Random r = new Random();
        int number = r.nextInt(100) + 1;
        // 2.猜这个数是多少
        Scanner sc = new Scanner(System.in);

        // 3.判断两个数字并给出提示
        int count = 1;

        while (true) {
            System.out.println("猜猜我是谁：");
            int tryit = sc.nextInt();
            count++;
            if (count == 10) {
                System.out.println("笨死了这都猜不中，答案是" + number);
                break;
            }

            if (tryit > number) {
                System.out.println("猜错啦！太大了捏，换小一点试试吧");
                System.out.println("已经猜了" + count + "次了哦");
            } else if (tryit < number) {
                System.out.println("猜错啦！太小了捏，换大一点试试吧");
                System.out.println("已经猜了" + count + "次了哦");

            } else {
                System.out.println("恭喜你，猜对啦！奖励你哦~");
                break;
            }
        }
    }
}
